const user = ({
    state: {
        id: '', // 用户id
        username: '', // 用户账号
        headphoto:'',//头像
        phone:'',//手机号码
        address:'',//地址
        sex:'',//性别
        mid:''//师傅编号
    },
    getters: {
        id: state => {
            let id = state.id
            if (!id) {
                id = JSON.parse(window.sessionStorage.getItem('id'))
            }
            return id
        },
        mid: state => {
            let mid = state.mid
            if (!mid) {
                mid = JSON.parse(window.sessionStorage.getItem('mid'))
            }
            return mid
        },
        username: state => {
            let username = state.username
            if (!username) {
                username = JSON.parse(window.sessionStorage.getItem('username'))
            }
            return username
        },
        headphoto: state => {
            let headphoto = state.headphoto
            if (!headphoto) {
                headphoto = JSON.parse(window.sessionStorage.getItem('headphoto'))
            }
            return headphoto
        },
        phone: state => {
            let phone = state.phone
            if (!phone) {
                phone = JSON.parse(window.sessionStorage.getItem('phone'))
            }
            return phone
        },
        address: state => {
            let address = state.address
            if (!address) {
                address = JSON.parse(window.sessionStorage.getItem('address'))
            }
            return address
        },
        email: state => {
            let email = state.email
            if (!email) {
                email = JSON.parse(window.sessionStorage.getItem('email'))
            }
            return email
        },
        sex: state => {
            let sex = state.sex
            if (!sex) {
                sex = JSON.parse(window.sessionStorage.getItem('sex'))
            }
            return sex
        },

    },
    mutations: {
        setId: (state, id) => {
            state.id = id
            window.sessionStorage.setItem('id', JSON.stringify(id))
        },
        setMid: (state, mid) => {
            state.mid = mid
            window.sessionStorage.setItem('mid', JSON.stringify(mid))
        },
        setUsername: (state, username) => {
            state.username = username
            window.sessionStorage.setItem('username', JSON.stringify(username))
        },
        setHeadphoto:(state,headphoto) => {
            state.headphoto = headphoto
            window.sessionStorage.setItem('headphoto',JSON.stringify(headphoto))
        },
        setPhone:(state,phone) => {
            state.phone = phone
            window.sessionStorage.setItem('phone',JSON.stringify(phone))
        },
        setAddress:(state,address) => {
            state.address = address
            window.sessionStorage.setItem('address',JSON.stringify(address))
        },
        setEmail:(state,email) => {
            state.email = email
            window.sessionStorage.setItem('email',JSON.stringify(email))
        },
        setSex:(state,sex) => {
            state.sex = sex
            window.sessionStorage.setItem('sex',JSON.stringify(sex))
        }
    }
})
export default user